package com.online_mall.commodity.service.impl;

import com.online_mall.commodity.dao.CommodityDao;
import com.online_mall.commodity.entity.Commodity;
import com.online_mall.commodity.service.CommodityService;
import com.online_mall.uitl.ResultFormat;
import com.online_mall.uitl.ResultUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * (Commodity)表服务实现类
 *
 * @author makejava
 * @since 2025-09-02 15:03:04
 */
@Service("commodityService")
@Transactional(rollbackFor = Exception.class)
public class CommodityServiceImpl implements CommodityService {
    @Resource
    private CommodityDao commodityDao;


    @Override
    public ResultFormat queryAll(Commodity commodity) {
        return ResultUtil.success(commodityDao.queryAll(commodity));
    }

    @Override
    public ResultFormat insert(Commodity commodity) {
        commodity.setCommodityId("商品"+System.currentTimeMillis());
        commodity.setHeat(0L);
        return ResultUtil.success(commodityDao.insert(commodity));
    }

    @Override
    public ResultFormat update(Commodity commodity) {
        return ResultUtil.success(commodityDao.update(commodity));
    }

    @Override
    public ResultFormat deleteById(String commodityId) {
        return ResultUtil.success(commodityDao.deleteById(commodityId));
    }

    @Override
    public ResultFormat addHeat(String commodityId) {
        return ResultUtil.success(commodityDao.addHeat(commodityId));
    }
}
